function flattenObject(obj) {
  if(obj==null || typeof obj !=="object") return obj;
  const res = {};
  const flatten = (val, key) => {
    if(val==null || typeof val!=='object') {
      res[key]=val
    }else if(Array.isArray(val)) {
      val.forEach((item,index)=>{
        flatten(item, key+'['+index+']')
      })
    }else {
      for(const _key in val) {
        flatten(val[_key], key? key+'.'+ _key : _key)
      }
    }
  }
  flatten(obj, '')
  return res;
}
const obj = {
  a: {
    b: 1,
    c: 2,
    d: { e: 5 },
  },
  b: [1, 3, { a: 2, b: 3 }],
  c: 3,
};
 console.log(flattenObject(obj))